//
//  HFViewController.m
//  TangQiang
//
//  Created by houfeng on 13-4-10.
//  Copyright (c) 2013年 Tieto. All rights reserved.
//

#import "HFViewController.h"
#import "MContent.h"
@interface HFViewController ()
{
    NSManagedObjectContext *managedObjectContext_;
    NSMutableArray *arr;
}
@end

@implementation HFViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    managedObjectContext_ = TangQiangAppDelegate.managedObjectContext;
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"MContent" inManagedObjectContext:managedObjectContext_];
    [fetchRequest setEntity:entity];
//    
//    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"user_name MATCHES %@",managerName];
//    [fetchRequest setPredicate:predicate];
    
    NSArray *managerList = [managedObjectContext_ executeFetchRequest:fetchRequest error:nil];
//    [fetchRequest release];
    arr = [[NSMutableArray alloc] init];
    [arr addObjectsFromArray:managerList];
    [fetchRequest release];
//    [managerList release];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arr count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"UITABLEVIEW";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text = ((MContent *)[arr objectAtIndex:indexPath.row]).details;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%d row is clicked;", indexPath.row);
}

@end
